﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.MultiTenancy;

namespace EcoSystem
{
    /// <summary>
    /// SQL脚本执行服务提供给Script引擎的封装类
    /// </summary>
    public interface IDataStoreScriptService
    {
        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<IEnumerable<TResult>> QuerySqlAsync<TResult>( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<dynamic> QuerySqlAsync( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<TResult> QueryFirstAsync<TResult>( string sql, Dictionary<string, object> parameters);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<dynamic> QueryFirstAsync( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<IEnumerable<TResult>> QueryStoreProcedureAsync<TResult>( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<IEnumerable<dynamic>> QueryStoreProcedureAsync( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="name"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<TResult> QueryStoreProcedureFirstAsync<TResult>( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<dynamic> QueryStoreProcedureFirstAsync( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<int> ExecuteSqlAsync( string sql, Dictionary<string, object> parameters = null);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        Task<int> ExecuteStoreProcedureAsync( string sql, Dictionary<string, object> parameters = null);


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        Task<TResult> GetCacheAsync<TResult>(string key) where TResult : class;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expiration"></param>
        /// <returns></returns>
        Task SetCacheAsync<TResult>(string key, TResult value, DateTimeOffset? expiration = null) where TResult : class;
    }
}
